import request from '@/utils/request'

export default {
  login: (data: any) => request({
    url: '/admin/auth/token',
    method: 'post',
    data: {
      ...data,
      grant_type: 'password',
      scope: ''
    },
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      'Authorization': 'Basic ' + btoa('easy-admin:123456'),
      'Accept-Language': 'zh_CN'
    }
  }),

  loginOptions: async (username: string) => request({
    url: '/admin/auth/login/options',
    method: 'get',
    params: {
      username: username
    },
    headers: {
      'Accept-Language': 'zh_CN'
    }
  }),

  loginVerify: (data: any) => request({
    url: '/admin/auth/token',
    method: 'post',
    data: {
      ...data,
      grant_type: 'passkey',
      scope: ''
    },
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      'Authorization': 'Basic ' + btoa('easy-admin:123456'),
      'Accept-Language': 'zh_CN'
    }
  }),

  registerOptions: async () => request.get('/admin/auth/register/options'),

  registerVerify: async (data: any) => request.post('/admin/auth/register/verify', data),

  userCredential: async (data: any) => request.get('/admin/auth/user/credential', data),

  deleteUserCredential: async (id: string) => request.delete('/admin/system/user/credential/' + id),

  getInfo: async () => request.get('/admin/auth/getInfo'),

  getRouters: async () => request.get('/admin/auth/getRouters'),

  getPermission: async () => request.get('/admin/auth/getPermission'),

  // 获取系统配置
  allConfig: async () => request.get('/admin/getConfigs'),

  // 退出方法
  logout: () => request.post('/admin/auth/logout'),

  // 生成验证码
  captchaGenerate: async () => request.get('/admin/captcha/generate'),

  // 验证验证码
  captchaCheck: async (data:any) => request.post('/admin/captcha/check',data),

  sendEmailCaptcha: async (data: any) => request.post('/admin/captcha/email/send', data),

  resetPassword: async (data: any) => request.put('/admin/reset/password', data),
}
